<?php

/**
 * Transaction form.
 *
 * @package    Amawal Invest
 * @subpackage form
 * @author     Ameen Shoman<amin.shoman@gmail.com>
 */
class NoClosingtransationForm extends TransactionForm
{
	public function configure()
	{

		$this->useFields(array(
		'date_from','date_to'
		));


		$this->widgetSchema['date_from'] = new sfWidgetFormTime();
		$this->validatorSchema['date_from'] = new sfValidatorTime();

		$this->widgetSchema['date_to'] = new sfWidgetFormTime();
		$this->validatorSchema['date_to'] = new sfValidatorTime();

		if( $this->getObject()->getTransactionType() == globals::NO_CLOSEING_LEAVE_END ){
			
			$this->widgetSchema['date_from']->setAttribute('readonly','readonly');
			$this->getWidgetSchema()->setHelp('date_from','This field is readonly');
			
		} else {

			$this->widgetSchema['date_to']->setAttribute('readonly','readonly');
			$this->getWidgetSchema()->setHelp('date_to','This field is readonly');
			
		}
		$old_post_validator = $this->getValidatorSchema()->getPostValidator();
		$new_post_validator = new sfValidatorSchemaCompare('date_to','>','date_from',array('throw_global_error'=>true),array('invalid'=>'The time-in should be greator than the time-out'));
		$this->getValidatorSchema()->setPostValidator($new_post_validator);
		//$this->getValidatorSchema()->setPostValidator(new sfValidatorAnd(array($old_post_validator,$new_post_validator)));

	}

}
